<!DOCTYPE html>
<!-- saved from url=(0013)about:internet -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <title>博客发布</title>
    <th:block th:replace="admin/_fragments :: somehead"></th:block>
    <link rel="stylesheet" th:href="@{/lib/editormd/css/editormd.min.css}">
    <script th:src="@{/lib/editormd/editormd.min.js}"></script>
</head>

<body>
    
    <nav th:replace="admin/_fragments :: backnav(1)"></nav>

    <div class="ui attached pointing menu">
        <div class="ui container">
            <a href="#" class="active orange item">博客发布</a>
            <a th:href="@{/admin/blogs}" class="item">博客列表</a>
        </div>

    </div>

    <div class="fluid container m-padded-tb-large">
        <div class="ui container">
            <form id="blog-form" th:action="@{/admin/blogs}" th:object="${blog}" method="POST" class="ui form">
				<input type="hidden" name="published"></input>
				<input type="hidden" name="id" th:value="*{id}"></input>
                <div class="required field">
                    <div class="ui left label input">
                        <div class="ui selection compact teal basic dropdown label">
                            <input type="hidden" name="flag" th:value="*{flag}==null ? '原创' : *{flag}">
                            <i class="dropdown icon"></i>
                            <div class="text">原创</div>
                            <div class="menu">
                                <div class="item" data-value="原创">原创</div>
                                <div class="item" data-value="转载">转载</div>
                            </div>
                        </div>
                        <input type="text" name="title" th:value="*{title}" placeholder="标题" style="width: 93%;" />
                    </div>
                    <div class="required field">
                        <div id="md-content" style="z-index: 1 !important;">
                            <textarea placeholder="博客内容" name="content" th:text="*{content}" style="display: none;"></textarea>
                        </div>

                    </div>
                    <div class="two fields">
                        <div class="required field">
                            <div class="ui left action labeled input">
                                <label class="ui compact teal basic label">分类</label>
                                <div class="ui fluid selection dropdown">
                                    <input type="hidden" name="type.id" th:value="*{type}!=null ? *{type.id}">
                                    <i class="dropdown icon"></i>
                                    <div class="default text">分类</div>
                                    <div class="menu">
                                    	<div th:each="type : ${types}" class="item" th:data-value="${type.id}" th:text="${type.name}">分类</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="field">
                            <div class="ui left action labeled input">
                                <label class="ui compact teal basic label">标签</label>
                                <div id="tag-dropdown" class="ui fluid selection multiple search dropdown">
                                    <input type="hidden" name="tagIds" th:value="*{tagIds}">
                                    <i class="dropdown icon"></i>
                                    <div class="default text">标签</div>
                                    <div class="menu">
                                        <div th:each="tag : ${tags}" class="item" th:data-value="${tag.id}" th:text="${tag.name}">标签</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="required field">
                        <div class="ui left labeled input">
                            <label class="ui teal basic label">首图</label>
                            <input type="text" name="firstPicture" th:value="*{firstPicture}" placeholder="图片地址" id="">
                        </div>
                    </div>
                    <div class="required field">
                    	<textarea name="description" th:text="*{description}" placeholder="博客描述..." maxlength="200"></textarea>
                    </div>

                    <div class="inline fields">
                        <div class="field">
                            <div class="ui checkbox">
                                <input type="checkbox" name="recommend" id="recommend" checked th:checked="*{recommend}" class="hidden">
                                <label for="recommend">推荐</label>
                            </div>
                        </div>
                        <div class="field">
                            <div class="ui checkbox">
                                <input type="checkbox" name="shareStatement" id="shareinfo" th:checked="*{shareStatement}" class="hidden">
                                <label for="shareinfo">转载声明</label>
                            </div>
                        </div>
                        <div class="field">
                            <div class="ui checkbox">
                                <input type="checkbox" name="appreciation" id="appreciation" th:checked="appreciation" class="hidden">
                                <label for="appreciation">赞赏</label>
                            </div>
                        </div>
                        <div class="field">
                            <div class="ui checkbox">
                                <input type="checkbox" name="commentabled" id="commentabled" th:checked="commentabled" class="hidden">
                                <label for="commentabled">评论</label>
                            </div>
                        </div>
                    </div>

                    <div class="ui error message"></div>

                    <div class="ui container m-padded-tb-default">
                        <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                        <button type="button" id="save-btn" class="ui secondary button">保存</button>
                        <button type="button" id="publish-btn" class="ui teal button">发布</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <br>
    <br>

    <footer th:replace="admin/_fragments :: footer" ></footer>

    <script>
        // 初始化markdown编辑器
        var contentEditor;
        $(function() {
            testEditor = editormd("md-content", {
                width: "100%",
                height: 640,
                syncScrolling: "single",
                path: "/lib/editormd/lib/"
            });
        });

        $('.m-menu-toggle').click(function() {
            $('.m-item').toggleClass('m-mobile-hide');
        });

        $('.ui.dropdown').dropdown({
            on: 'hover'
        });
        
       /*  $('#tag-dropdown').dropdown({
        	allowAdditions: true
        }); */
        

        $('.ui.form').form({
            fields: {
                title: {
                    identifier: 'title',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入博客标题'
                    }]
                },
                content: {
                    identifier: 'content',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入博客内容'
                    }]
                },
                typeId: {
                    identifier: 'typeId',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入博客类型'
                    }]
                },
                firstPicture: {
                    identifier: 'firstPicture',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入首图地址'
                    }]
                },
                description: {
                    identifier: 'description',
                    rules: [{
                        type: 'empty',
                        prompt: '请输入博客描述'
                    }]
                }
            }
        });
        
        $('#save-btn').click(function (){
        	$('[name="published"]').val(false);
        	$('#blog-form').submit();
        });
        
        $('#publish-btn').click(function (){
        	$('[name="published"]').val(true);
        	$('#blog-form').submit();
        });
        
    </script>
</body>

</html>